<?php
/**
 *  File Defination 
 *  - Static Page Manger
 -------------------------------------------------------------------  
 *  Apprain : Content Management Framework <http://www.apprain.com/>
 *  Download link: http://www.apprain.com/download
 *  Docs link: http://www.apprain.com/docs
 -------------------------------------------------------------------
 *  License text http://www.opensource.org/licenses/mit-license.php 
 *  About MIT license <http://en.wikipedia.org/wiki/MIT_License/>
 */
$page_current['title'] 				= isset($page_current['title']) ? $page_current['title'] : "";
$page_current['page_title'] 		= isset($page_current['page_title']) ? $page_current['page_title'] : "";
$page_current['meta_keywords'] 		= isset($page_current['meta_keywords']) ? $page_current['meta_keywords'] : "";
$page_current['meta_description'] 	= isset($page_current['meta_description']) ? $page_current['meta_description'] : "";
$page_current['content'] 			= isset($page_current['content']) ? $page_current['content'] : "";


/*  Calling validation 	 */
    echo App::Load("Helper/Javascript")->validation_map(array('_errBg'=>ERROR_BACKGROUND,'_dflBg'=>"#CECECE",'_autoSubmit'=>'true','_errorMark'=>'inline','_errToolTips'=>'false'));

if( $action == 'create'):
	echo $this->get_tag("form",array("action"=>$this->baseurl("/page/manage/{$action}"),"class"=>"app_form app_validation","method"=>"post"));
else:
	echo $this->get_tag("form",array("action"=>$this->baseurl("/page/manage/{$action}/{$page_id}"),"class"=>"app_form","id"=>"auto_chk_submit","method"=>"post"));
endif;	

    echo $this->callElement("default/tools/tool_bar",array("buttons"=>array( array("type"=>"save"),array("type"=>"delete"), array('type' => 'file_manager'),array('type'=>'back')) ,"title" => "Static page manager"));

        echo $this->callElement('default/tools/message', array('caption' =>'Message','type' => 'error', 'message' => $errors));

        $Grid = App::Module('DataGrid')->setDisplay('FormListing');
        if( $action == 'create'):
            $Grid->addRow("Page Name",App::load("Helper/Html")->inputTag('data[Page][name]', "",array("class" => "app_input check_notempty","id" => "page_name")));
        else:
        	$Grid->addRow("Select Page",App::load("Helper/Html")->selectTag('data[Page][id]', $static_page_arr,$page_id,array("id" => "page_id","style"=>"width:200px")) . " " . App::Helper('Html')->linkTag($this->baseurl("/page/view/{$static_page_arr[$page_id]}"),'View Page',array("target"=>"_blunk")));        
        endif;
        
        if( $this->get_config('disable_page_meta_options') != "Yes"):
            $Grid->addRow("Page Meta Tile",App::load("Helper/Html")->textareaTag('data[Page][page_title]', $page_current['page_title'],array("class" => "app_input","id" => "page_title")))
                 ->addRow("Meta Keywords",App::load("Helper/Html")->textareaTag('data[Page][meta_keywords]', $page_current['meta_keywords'],array("class" => "app_input","id" => "meta_keywords")))
                 ->addRow("Meta Descriptions",App::load("Helper/Html")->textareaTag('data[Page][meta_description]', $page_current['meta_description'],array("style"=>"overflow:none","class" => "app_input","id" => "meta_description")));
        endif;
        $Grid->addRow("Tile",App::load("Helper/Html")->inputTag('data[Page][title]', $page_current['title'],array("class" => "app_input","id" => "title")))
             ->addRow("Content",App::load("Helper/Html")->textareaTag('data[Page][content]', $page_current['content'],array("rows" => "32","class" => "app_input richtexteditor","id" => "page_content")))
             ->render();
        
    /*Call the tools bar*/
    echo $this->callElement("default/tools/tool_bar",array("buttons"=>array( array('type'=>'save'), array('type'=>'back') ) ,"position" => 'bottom'));
echo $this->get_tag("/form");

echo "<script type=\"text/javascript\">
    window.addEvent('domready', function() 
    {
        $('page_id').addEvent('change', function()
        {
            if( this.value != '')
            {
                window.location = base + '/page/manage/update/' + this.value;
            }
        });
    });
</script>";